package com.twu.biblioteca;

import java.util.Scanner;

public class BibliotecaApp {

    public static final int START_APP = -1;
    public static final int EXIT_APP = 0;
    private static BookShelf bookShelf = new BookShelf();
    private static MovieShelf movieShelf = new MovieShelf();
    public static Scanner input = new Scanner(System.in);

    private static App biblioteca = new App(bookShelf, movieShelf);

    public static void main(String[] args) throws BookAlreadyExistsException {

        BibliotecaApp.initialise();

        BibliotecaApp.print(biblioteca.getWelcomeMessage());

        int option = START_APP;

        while (option != EXIT_APP) {

            BibliotecaApp.print(biblioteca.getMainMenuList());

            option = BibliotecaApp.getUserInput();

            if (option == EXIT_APP) break;

            print(biblioteca.getMainMenuResponse(option));

            if (biblioteca.hasSubMenuFor(option)) {

                int option2 = BibliotecaApp.getUserInput();

                print(biblioteca.getSubMenuResponse(option, option2));

            }
        }

    }

    private static void initialise() throws BookAlreadyExistsException {
        populateBookShelf();
        populateMovieShelf();
        populateUsers();
    }

    public static void print(String output) {
        System.out.println(output);
    }

    private static void populateUsers(){
        UserList.add(new User("Timothy Akampa", "akampati@thougthworks.com", "+256775019449", "akampatimmy"));
    }


    private static int getUserInput() {
        System.out.print(">>");
        return input.nextInt();
    }

    public static void populateBookShelf() throws BookAlreadyExistsException {
        bookShelf.addBook(new Book("The Art Of War", "Sun Tzu", 32422312));
    }

    public static void populateMovieShelf() {
        movieShelf.addMovie(new Movie("Sky Fall", 2012, "Justin Lin", 8));
        movieShelf.addMovie(new Movie("The Race 2", 2013, "Parker Vim", 8));
        movieShelf.addMovie(new Movie("After Earth", 2013, "Night Shyamalan", 4));
        movieShelf.addMovie(new Movie("Iron Man 3", 2013, "Shane Black", 7));
        movieShelf.addMovie(new Movie("Oblivion", 2013, "Antonio Spinner", 3));
        movieShelf.addMovie(new Movie("Man of Steel", 2013, "Zack Snyder"));
        movieShelf.addMovie(new Movie("The Avengers", 2012, "Packer Vim"));
    }

}
